import { BaseService } from '@/base/base.service';
import { pageData } from '@/util/util';
import { Injectable } from '@nestjs/common';
import { coinService } from '@prisma/client';
import { CreateCoinServiceDto } from './dto/create-coin-service.dto';
import { UpdateCoinServiceDto } from './dto/update-coin-service.dto';

@Injectable()
export class CoinServiceService {

  constructor(private readonly baseService: BaseService){}

  async create(createCoinServiceDto: CreateCoinServiceDto) {
    await this.baseService.coinService.create({
      data: {
        ...createCoinServiceDto
      }
    })
    return '添加成功'
  }

  async findAll() {
    return await this.baseService.coinService.findMany();
  }

  async findPage(query: any) {
    return await pageData<coinService>('coinService', query)
  }

  async findOne(id: string) {
    return await this.baseService.coinService.findUnique({
      where: {
        id
      }
    });
  }

  async update(id: string, updateCoinServiceDto: UpdateCoinServiceDto) {
    await this.baseService.coinService.update({
      where: {
        id
      },
      data: updateCoinServiceDto
    })
    return '修改成功'
  }

  async remove(id: string) {
    await this.baseService.coinService.delete({
      where: {
        id
      }
    })
    return '删除成功'
  }

  manyRemove(idList: string[]) {
    idList.forEach(async item => {
      await this.remove(item)
    })
    return '删除成功'
  }
}
